import 'package:flutter/material.dart';
import './dashboard_page.dart';
import './user_page.dart';
import './order_page.dart';
import './settings_page.dart';
// class HomePage extends StatelessWidget {
//   const HomePage({super.key});

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(title: const Text("首页")),
//       body: Center(
//         child: ElevatedButton(
//           onPressed: () {
//             Navigator.pushNamed(context, '/login');
//           },
//           child: const Text("去登录"),
//         ),
//       ),
//     );
//   }
// }


import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;

  // 模拟几个后台菜单
  final List<String> _menuItems = [
    "仪表盘",
    "用户管理",
    "订单管理",
    "设置",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("后台管理系统"),
        actions: [
          IconButton(
            onPressed: () {},
            icon: const Icon(Icons.notifications),
          ),
          IconButton(
            onPressed: () {},
            icon: const Icon(Icons.account_circle),
          ),
        ],
      ),
      body: Row(
        children: [
          // 左侧导航栏
          NavigationRail(
            selectedIndex: _selectedIndex,
            onDestinationSelected: (index) {
              setState(() {
                _selectedIndex = index;
              });
            },
            labelType: NavigationRailLabelType.all,
            destinations: _menuItems.map((item) {
              return NavigationRailDestination(
                icon: const Icon(Icons.circle),
                label: Text(item),
              );
            }).toList(),
          ),

          // 主体内容
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: _buildPageContent(),
            ),
          ),
        ],
      ),
    );
  }

  // 根据选中的菜单显示不同的内容
  // ✅ 用独立的组件代替原来的写法
  Widget _buildPageContent() {
    switch (_selectedIndex) {
      case 0:
        return const DashboardPage();
      case 1:
        return const UserPage();
      case 2:
        return const OrderPage();
      case 3:
        return const SettingsPage();
      default:
        return const Center(child: Text("请选择一个功能"));
    }
  }

}
